package com.leco.exam.webcommon.common;

import com.leco.exam.webcommon.utils.RequestUtil;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;

@Slf4j
public class BaseExceptionHandler {

	protected String relatedContext(){
		HttpServletRequest request = RequestUtil.getRequest();
		StringBuffer sb = new StringBuffer();
		sb.append("url: ").append(request.getRequestURI()).append("\n");
		sb.append("ua: ").append(request.getHeader("User-Agent")).append("\n");
		sb.append("refer: ").append(request.getHeader("referer")).append("\n");
		sb.append("log error form controller\n");
		return sb.toString();
	}

	protected void exceptionLog(Exception ex){
		log.error(relatedContext() , ex);
	}

	protected void exceptionWarn(Exception ex){
		log.warn(relatedContext() , ex);
	}

	protected void exceptionError(Exception ex){
		log.error(relatedContext() , ex);
	}
}
